package effectiveJava.compare;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.CompareToBuilder;

/**
 * Created by dongyuncong on 2017/8/24.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
class CompareBase implements Comparable<CompareBase> {
    private Integer id;
    private String position;
    private Integer age;


    /*Comparable 接口实现类的默认排序法*/
    @Override
    public int compareTo(CompareBase o) {
//        return id.compareTo(o.getId());
        /*todo 使用apache CompareToBuilder 构建比较器*/
        return new CompareToBuilder()
                .append(id, o.getId())      /*先以id排序*/
                .append(age, o.getAge())    /*接着年龄*/
                .append(position, o.getPosition())  /*然后职位*/
                .build();
    }

}
